package com.codeduck.bean.entity;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * Spring提供了一个BeanPostProcessor接口，俗称Bean后置通知处理器，它提供了两个方法
 *  postProcessBeforeInitialization: 在Bean的初始化方法调用之前执行；
 *  postProcessAfterInitialization：在Bean的初始化方法调用之后执行。
 * 向 Spring 注册 BeanLifeCycleIVPostProcessor : {@link com.codeduck.bean.config.BeanLifeCycleConfigIV}
 *
 * @author: <a href="mailto:codeduck@163.com">Codeduck</a>
 * @createDate: 2021-12-23
 */
@Slf4j
public class BeanLifeCycleIVPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("beanLifeCycleIV".equals(beanName)) {
            log.warn("BeanPostProcessor#postProcessBeforeInitialization 方法调用完毕");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("beanLifeCycleIV".equals(beanName)) {
            log.warn("BeanPostProcessor#postProcessAfterInitialization 方法调用完毕");
        }
        return bean;
    }
}
